<?php

namespace Home\Model;

class MatchModel extends CommonModel {

    public function findMatchByMatchId($dt){
        $flt = $dt['match_id'];
        $rs = $this->find($flt);
        return $rs;
    }

    public function findMatchByPlayerId($player_id){
        $sql = "select * " .
               "from kick_match a, kick_match_team_player b " .
               "where 1 " .
               "and a.match_id=b.match_id " .
               "and b.player_id={$player_id} " .
               "" .
               "order by a.create_time desc " .
               ";";
        $dt = $this->query($sql);
        return $dt;
    }

    public function createMatch(){
        // insert
        $this->_auto = array(
            array('create_time','time',1,'function'),
            array('update_time','time',3,'function'),
        );
        $dt = $this->create();
        if (empty($_POST['match_id'])) {
            $rs = $this->add($dt);
            // insert msg
            $this->mdlMsg = D('msg');
            $this->mdlMsg->createMsg($rs, 'match');
        } else {
            $rs = $this->save($dt);
        }


        $ret = array();
        if ($rs) {
            $ret['status'] = true;
            $ret['msg'] = '操作成功！';
            $ret['dt']['match_id'] = $rs;
        } else {
            $ret['status'] = false;
            $ret['msg'] = $this->getError();
        }
        return $ret;
    }

}
